<% content_for :title_bar do %>
  <%= render :partial => 'projects/nav', :locals => {:project => @project} %>
<% end %>

<h2>Import stories</h2>

<p>
You can bulk import stories in comma separated variable (CSV) format.  The
first line of the CSV must contain the correct headers for the import to
succeed.  You can download a
<a href="/Fulcrum_Import_Template.csv">CSV template</a> with the correct
headers to get you started.
</p>
<p>
Fulcrum will try and match any user names found in the CSV with members of
your project.  Be sure to add members with the correct names before importing
if you want these to match up.
</p>
<p><em>Note: You can also use a CSV export from Pivotal Tracker.</em></p>
<%= form_tag import_upload_project_stories_path(@project), :multipart => true %>
  <%= file_field_tag :csv %>
  <%= submit_tag :import %>
</form>

<% if @stories %>
  <h2>Import results</h2>

  <table id="import">
    <thead>
      <tr>
        <th>Row</th>
        <th>Story</th>
        <th>Type</th>
      </tr>
    </thead>
    <tbody>
      <% @stories.each_with_index do |story, index| %>
        <% if story.valid? %>
        <tr class="valid">
          <td><%= index + 1 %></td>
          <td><%= story.title %></td>
          <td><%= story.story_type %></td>
        </tr>
        <% else %>
          <tr class="invalid">
            <td><%= index + 1 %></td>
            <td colspan="2">
              <%= story.errors.full_messages.join(', ') %>
            </td>
          </tr>
        <% end %>
      <% end %>
    </tbody>
  </table>
<% end %>
